﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ZhiAo.WebLib.Data;
using System.Web.UI.WebControls;
using System.Collections;
using ZhiAo.Management.Data;

namespace ZhiAo.Management
{
    public class Utils
    {
        public static DataTable GetBindData(string fields, string tableName, string conditon)
        {
            string sql = "SELECT {0} FROM {1} WHERE 1=1 {2}";
            sql = string.Format(sql, fields, tableName, conditon);
            return DBHelper.GetDataTable(sql);
        }

        public static void BindDrpData(DropDownList drp, DataTable dt, bool addEmp)
        {
            drp.DataValueField = "CODE";
            drp.DataTextField = "NAME";
            if (addEmp)
            {
                DataRow dr = dt.NewRow();
                dr["CODE"] = "";
                dr["NAME"] = "";
                dt.Rows.InsertAt(dr, 0);
            }
            drp.DataSource = dt;
            drp.DataBind();
        }

        public static DataTable GetSiteData()
        {
            return GetBindData(" RTRIM(STCD) AS CODE,STNM AS NAME", "SQ_STBPRP_B", " AND STCD IN(" + QueryData.GetSiteIds(Utility.GetSpecificFunctionId()) + ")");
        }

        public static DataTable GetRainType()
        {
            DataTable dt = new DataTable();
            DataColumn dc = new DataColumn();
            dc.ColumnName = "CODE";
            dt.Columns.Add(dc);
            dc = new DataColumn();
            dc.ColumnName = "NAME";
            dt.Columns.Add(dc);

            DataRow dr = dt.NewRow();
            dr["CODE"] = "5";
            dr["NAME"] = "五分钟";
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr["CODE"] = "60";
            dr["NAME"] = "时雨量";
            dt.Rows.Add(dr);
            return dt;
        }


        public static DataTable CreateTable(string[][] arr)
        {
            DataTable dt = new DataTable();
            DataColumn dc = new DataColumn();
            dc.ColumnName = "CODE";
            dt.Columns.Add(dc);
            dc = new DataColumn();
            dc.ColumnName = "NAME";
            dt.Columns.Add(dc);
            DataRow dr = null;
            for (int a = 0; a < arr.Count(); a++)
            {
                dr = dt.NewRow();
                dr["CODE"] = arr[a][0];
                dr["NAME"] = arr[a][1];
                dt.Rows.Add(dr);
            }

            return dt;
        }
    }
}
